# coding: utf-8
#程序主文件

import ftplib

#自定义文件
import RSA_op
import SHA256_op
import File
import Certificate_User
import FTP_op


if __name__ == "__main__":
    #host = '127.0.0.1'
    host = input("请输入FTP服务器IP地址:")
    print("尝试连接FTP服务器:"+host)
    try:
        ftp = FTP_op.connect_ftp(host)
        print("尝试连接FTP服务器:"+host+" 成功\n")
    except:
        print("尝试连接FTP服务器:"+host+" 失败\n")
        exit(-1)
    name = input("请输入证书使用者姓名:")
    print("欢迎"+name)
    while True:
        print("请选择功能:")
        print("1. 生成公钥和私钥")
        print("2. 生成证书申请文件")
        print("3. 验证证书")
        print("4. 下载证书")
        print("0. 退出")
        try:
            choose_num = int(input("请输入:"))
        except:
            choose_num = -1
        if choose_num==1:
            File.create_key_file(name)
        elif choose_num==2:
            Certificate_User.apply_certificate(ftp, name)
        elif choose_num==3:
            Certificate_User.verify_certificate(ftp, name)
        elif choose_num==4:
            Certificate_User.download_certificate(ftp, name)
        elif choose_num==0:
            exit()
        else:
            choose_num = int(input("输入错误，请输入:"))
    